<% include ../header.ejs %>

<header data-am-widget="header" data-am-sticky class="am-header am-header-default" id="appTemplates-Nav">
    <div class="am-header-left am-header-nav">
        <a href='javascript:history.go(-1)'>
            <img class="am-header-icon-custom" src="data:image/svg+xml;charset&#x3D;utf-8,&lt;svg xmlns&#x3D;&quot;http://www.w3.org/2000/svg&quot; viewBox&#x3D;&quot;0 0 12 20&quot;&gt;&lt;path d&#x3D;&quot;M10,0l2,2l-8,8l8,8l-2,2L0,10L10,0z&quot; fill&#x3D;&quot;%23fff&quot;/&gt;&lt;/svg&gt;" alt=""/>
        </a>
    </div>

    <h1 class="am-header-title">
        <a id="Typeface-whitecolor">上传文档</a>
    </h1>

    <div class="am-header-right am-header-nav">
        <a onclick="save()">保存</a>
    </div>

</header>

<form class="am-form" method="post" action="add" enctype="multipart/form-data" data-am-validator   ng-app="knowledgeList" ng-controller="listController">
    <fieldset>
        <div class="am-form-group">
            <label for="attachmentName">文档：</label>
            <div class="am-g am-g-collapse">
                <div class="am-u-sm-9">
                    <input type="text" name="attachmentName" class="am-form-field" style="border-right:none;" placeholder="附件" required readonly>
                </div>
                <div class="am-u-sm-3 am-form-file">
                    <button type="button" class="am-form-field" style="color: #fff;background-color: #0e90d2;border-color: #0e90d2;"><i class="am-icon-cloud-upload"></i> 上传</button>
                    <input id="doc-form-file" name="file" type="file" multiple>
                </div>
            </div>
        </div>
        <div class="am-form-group">
            <label for="content">内容：</label>
            <textarea rows="5" name="content" placeholder="内容简介" required></textarea>
        </div>
        <div class="am-form-group">
            <label for="tag">标签：</label>
            <input type="text" name="tag" placeholder="标签" required>
        </div>
        <div class="am-form-group">
            <label for="tag">文档分类：</label>
            <select data-am-selected="{btnWidth:'100%'}" ng-model = "changeGroupId" name = "knowledgegroup" placeholder="选择分类"  >
                <option value="{{item.id}}"  ng-repeat="item in types" >{{item.name}}</option>
            </select>
        </div>
        <div class="am-form-group">
            <label for="tag">子项栏目：</label>
            <select data-am-selected="{btnWidth:'100%'}" name = "knowledgegroup" placeholder="选择子项"  >
                <option value="" >选择子项</option>
                <option value="{{g.id}}"  ng-repeat="g in groupList ">{{g.name}}</option>
            </select>
        </div>
    </fieldset>
</form>

<script>
    var hasFile = false;
    $(function() {
        $('#doc-form-file').on('change', function() {
            var fileNames = [];
            $.each(this.files, function() {
                fileNames.push(this.name);
            });
            hasFile = fileNames.length>0;
            $('input[name=attachmentName]').val(fileNames.join());
            if (hasFile){
                $('input[name=attachmentName]').removeAttr('readonly');
            }else{
                $('input[name=attachmentName]').attr('readonly','readonly');
            }
        });
    });

    function save() {
        hasFile && $('.am-form').submit();
    }
</script>
<script src="/javascripts/app/knowledge/knowledge.js"></script>

<% include ../footer.ejs %>